package @{crud.properties.base_package}.@{crud.properties.model}.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import @{crud.properties.base_package}.@{crud.properties.model}.entity.@{crud.table.className};
import @{crud.properties.base_package}.@{crud.properties.model}.service.@{crud.table.className}Service;
import cn.lvji.core.vo.Grid;
import cn.lvji.core.vo.Response;
import cn.lvji.core.vo.PageRequest;

/**
 * @{crud.table.remarks}: 后端controller类
 * 
 * @author generator
 */
@RestController
public class @{crud.table.className}Controller {
    public class Page extends PageRequest<@{crud.table.className}>{
    }
    
    private @{crud.table.className}Service @{strutils.toLowerCaseFirst(crud.table.className)}ServiceImpl;
    
    @Autowired
    private @{crud.table.className}Controller(@{crud.table.className}Service @{strutils.toLowerCaseFirst(crud.table.className)}ServiceImpl){
        this.@{strutils.toLowerCaseFirst(crud.table.className)}ServiceImpl = @{strutils.toLowerCaseFirst(crud.table.className)}ServiceImpl;
    }
    
    /**
     * 新增@{crud.table.remarks}
     * 
     * 
     * @param @{strutils.toLowerCaseFirst(crud.table.className)} 实体对象
     * @return response
     */
    @PostMapping("/pt/@{strutils.toLowerCaseFirst(crud.table.className)}")
    public Response<Void> save(@RequestBody @{crud.table.className} @{strutils.toLowerCaseFirst(crud.table.className)}){
        return @{strutils.toLowerCaseFirst(crud.table.className)}ServiceImpl.save(@{strutils.toLowerCaseFirst(crud.table.className)});
    }
    
    
    /**
     * 查询@{crud.table.remarks}
     * 
     * 
     * @param id 主键
     * @return response
     */
    @GetMapping("/pb/@{strutils.toLowerCaseFirst(crud.table.className)}/{id}")
    public Response<@{crud.table.className}> get(@PathVariable("id") Long id){
        Response<@{crud.table.className}> res = new Response<@{crud.table.className}>();
        @{crud.table.className} @{strutils.toLowerCaseFirst(crud.table.className)} = @{strutils.toLowerCaseFirst(crud.table.className)}ServiceImpl.get(id);
        res.setData(@{strutils.toLowerCaseFirst(crud.table.className)});
        return res;
    }
    
    
    /**
     * 分页查询@{crud.table.remarks}
     * 
     * 
     * @param request 分页搜索对象
     * @return response
     */
    @GetMapping("/pb/@{strutils.toLowerCaseFirst(crud.table.className)}/action/search")
    public Response<Grid<@{crud.table.className}>> list(Page request){
        return @{strutils.toLowerCaseFirst(crud.table.className)}ServiceImpl.list(request.buildPage(), request.getFilter());
    }

    
    /**
     * 更新@{crud.table.remarks}
     * 
     * 
     * @param param 实体对象
     * @return response
     */
    @PutMapping("/pt/@{strutils.toLowerCaseFirst(crud.table.className)}")
    public Response<Void> update(@RequestBody @{crud.table.className} param){
        return @{strutils.toLowerCaseFirst(crud.table.className)}ServiceImpl.update(param);
    }
    
    
    /**
     * 删除@{crud.table.remarks}
     * 
     * 
     * @param id 主键
     * @return response
     */
    @DeleteMapping("/pv/@{strutils.toLowerCaseFirst(crud.table.className)}/{id}")
    public Response<Void> delete(@PathVariable("id") Long id){
        return @{strutils.toLowerCaseFirst(crud.table.className)}ServiceImpl.delete(id);
    }
    
    
}